package com.example.smartcity.ui.home.adapter

import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.example.smartcity.R
import com.example.smartcity.SmartCityApplication.Companion.context
import com.example.smartcity.ui.AcNews.NewSFlashShowActivity
import com.example.smartcity.ui.home.model.HotEntity

/**
 *  ANDROID STUDIO @version 2022.1
 *          @email 2506789532@qq.com  @ikun
 *  time: 2023/1/22 15:44
 **/
class HotRecyclerViewAdapter(val v: View, val listData: List<HotEntity>) : RecyclerView.Adapter<HotRecyclerViewAdapter.ViewHolder>(){
    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view){
        // 获取控件
        val HotImageView = view.findViewById<ImageView>(R.id.HotImageView)
        val HotTitle = view.findViewById<TextView>(R.id.HotTitle)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val root = LayoutInflater.from(parent.context).inflate(R.layout.recyclerview_item_hot, parent, false)
        val view = ViewHolder(root)
        view.itemView.setOnClickListener {
            val intent = Intent(parent.context, NewSFlashShowActivity::class.java)
            intent.putExtra("hot", listData[view.position].title)
            parent.context.startActivity(intent)
        }

        return view
    }

    override fun getItemCount() = listData.size

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val data = listData[position]
        Glide.with(v)
            .load(data.cover)
            .into(holder.HotImageView)
        holder.HotTitle.text = data.title
    }
}